package wxk.interview.serializable;

import java.io.*;

/**
 * @author wangxuekai
 * @version 2.2
 * @Date 2017/3/9.
 * @since 2.2
 */
public class PersonStaticField implements Serializable {
    private static final long serialVersionUID = 3464658339959142367L;
    private String name;

    public PersonStaticField(String name) {
        this.name = name;
    }

    private static int version = 1;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "PersonStaticField{" +
                "name='" + name + '\'' +
                '}';
    }

    public static void main(String[] args){
        PersonStaticField personStaticField = new PersonStaticField("ss");
        File file = new File("personStaticField.out");

        try {
            ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
            outputStream.writeObject(personStaticField);
            PersonStaticField.version = 2;
            ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file));
            PersonStaticField newP = (PersonStaticField) inputStream.readObject();

            System.out.println(newP);
            System.out.println(PersonStaticField.version);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
